import { getListApi } from "@/api/managementCenter/driverManagement";

export default function OperationHook(state: Base.GeneraDataType) {
  const { tableData, searchForm, loading, dialogOpts, drawerOpts } = state;
  const searchHandle = () => {
    searchForm.pageNum = 1;
    getData();
  };
  const getData = () => {
    const params = {
      ...searchForm
    };
    loading.value = true;
    return getListApi(params)
      .then((res: any) => {
        const { code, data } = res;
        if (code === 200) {
          tableData.value = data.records || [];
          searchForm.total = Number(data.total);
        }
      })
      .finally(() => (loading.value = false));
  };
  const distributionAreaHandle = (row: DriverManagement.ListRows) => {
    dialogOpts.title = "分配区域";
    dialogOpts.width = "820px";
    dialogOpts.component = "DistributionArea";
    dialogOpts.passData = row;
    dialogOpts.visible = true;
  };
  const showAreaHandle = (row: DriverManagement.ListRows) => {
    drawerOpts.title = "收货区域";
    drawerOpts.width = "1000px";
    drawerOpts.component = "ReceivingArea";
    drawerOpts.passData = row;
    drawerOpts.visible = true;
  };
  return {
    searchHandle,
    getData,
    distributionAreaHandle,
    showAreaHandle
  };
}
